package day11.sorts;

import java.util.TreeSet;

public class Piao implements Comparable<Piao>{
    private int id;

    private String name;

    private double price;

    public Piao() {
    }

    public Piao(int id, String name, double price) {
        this.id = id;
        this.name = name;
        this.price = price;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Piao{");
        sb.append("id=").append(id);
        sb.append(", name='").append(name).append('\'');
        sb.append(", price=").append(price);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public int compareTo(Piao o) {
        return (int) (o.price - price);
    }
}
class TestPiao{
    public static void main(String[] args) {
        TreeSet<Piao> sets = new TreeSet<>();

        Piao p1 = new Piao(1,"张之洞",3000.0d);
        Piao p2 = new Piao(2,"张洞",1000.0d);
        Piao p3 = new Piao(3,"张开洞",2000.0d);

        sets.add(p1);
        sets.add(p2);
        sets.add(p3);

        for (Piao set : sets) {
            System.out.println(set);
        }
    }
}